<?php

abstract class Core_Library_Model {

    public function insert($tableName, $vars, $values) {
        if (is_array($vars)) {
            $vars = implode(', ', $vars);
        }
        if (is_array($values)) {
            $values = implode("', '", $values);
        }
        $values = "('" . $values . "')";
        $sql = 'insert into ' . "{$tableName}" . '(' . "{$vars}" . ') values ' . "{$values}" . ';';
        // echo $sql; die;
        mysql_query($sql) or die(mysql_error());

        // mysql_query($sql) or die (mysql_error());
    }

    public function update($tableName, $vars, $values) {
        if (is_array($vars)) {
            $vars = implode(', ', $vars);
        }
        if (is_array($vars)) {
            $values = implode(', ', $values);
        }
        $sql = 'update' . $tableName . 'set' . '';
    }

    /**
     *
     * @param type $var
     * @param type $tablename
     * @param type $value
     * select $var from $tablename where $param = $value
     */
    public function recordIsset($var, $tableName, $param, $value) {
        $sql = 'select ' . $var . ' from ' . $tableName . ' where ' . $param . ' = ' . "'" . $value . "'" . ';';
        $result = mysql_query($sql) ;
        $user_row = mysql_fetch_array($result);
        if (mysql_num_rows($result) > 0) {
            return true;
        } else {
            return false;
        }
    }

    public function getData($vars, $tableName, $param, $value) {
        if (is_array($vars)) {
            $vars = implode(', ', $vars);
        }
        $sql = 'select ' . $vars . ' from ' . $tableName . ' where ' . $param . ' = ' . "'" . $value . "'" . ';';
        //print_r($sql); die;
        $result = mysql_query($sql);
        //var_dump($result); die;
        $user_row = mysql_fetch_assoc($result);
        unset($result);
        return $user_row;
    }

    public function getUserData($vars, $usertype, $userid) {
        if (is_array($vars)) {
            $vars = implode(', ', $vars);
        }
        $sql = 'select ' . $vars
                . ' from users inner join users_types on '
                . 'users.users_types_users_typesid = users_types.users_typesid '
                . 'where users_types.users_typesid = '
                . $usertype . ' and users.userid = '
                . $userid;
        echo $sql;
        $result = mysql_query($sql);
        $user_row = mysql_fetch_assoc($result);
        unset($result);
        return $user_row;
    }

}

?>
